import { getAllColumnMap } from "@/api/adminColumnMapApi";

export type MapItem = {
  id: number;
  originalName: string;
};
export type QueryType = {
  page: number;
  size: number;
  keyword?: string;
};

export async function mapSelectFetcher(params: {
  page: number;
  size: number;
  keyword: string;
}) {
  // 按你的后端参数名对齐（若关键字不是 keyword，请改此处的字段名）
  const query = <QueryType>{
    page: params.page,
    size: params.size
  };
  if (params.keyword && params.keyword.trim()) {
    // 1) 若后端字段名就是 keyword：
    query.keyword = params.keyword.trim();
  }

  const res = await getAllColumnMap(query);
  // 兼容返回结构
  const records: MapItem[] = res?.data?.records ?? res?.records ?? [];
  const total = res?.data?.total ?? res?.total;

  return { list: records, total };
}
